package top.hspstudy.property.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.hspstudy.property.entity.User;
import top.hspstudy.property.entity.UserBo;
import top.hspstudy.property.service.UserService;
import top.hspstudy.property.utils.R;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * list 获取全部的
     * save 添加一个
     * saveBatch 添加一堆
     * updateById 主键改 传user
     */
    @GetMapping("/deleteUsers")
    public R findAllUsers(String username){
       userService.deleteByUsername(username);
       return R.success("","成功！");
    }

    /**
     *
     * @param ub
     * @return
     */
    @PostMapping("/getUsersByUsernameAndPassword")
    public R getUsersByUsernameAndPassword(@RequestBody UserBo ub){
        Integer count = userService.getByUsername(ub.getUsername());
        if(count > 0){
            Integer count2 = userService.getByUsernameAndPassword(ub);
            if(count2 >0){
                return R.success(count2,"登陆成功！");
            }
        }else{
            return R.error("账号不存在！");
        }
        return R.error("密码错误！");
    }

}
